#pragma once

#include <iostream>
#include <string>
#include <sstream>
#include "Util.hpp"

using namespace std;

const string SSEP = "\r\n";
const string DEFAULT_PATH = "./wwwroot";
//默认主界面
const string HOME_PATH = "index.html";

class HttpRequest
{
public:
    HttpRequest()
    {
    }
    ~HttpRequest()
    {
    }

    void Parse()
    {
        string line = Util::getOneLine(reqBuffer,SSEP);
        if(line.empty())
        {
            return;
        }
        // 有了请求端的第一行数据
        stringstream ss(line);
        ss >> moder >> url >> version;//按空格依次填充到成员变量中

        //添加路径
        path += DEFAULT_PATH;
        //手动路径 /wwwroot/a/b/c.html
        path += url;
        if(path[path.size()-1] =='/')
        {
            path += HOME_PATH;
        }
    }

public:
    //  Get url version-1.1
    string reqBuffer;  //从这个缓冲区拿取浏览器的req内容
    string moder;
    string url;
    string version;
    string path;
};

class HttpResponse
{
public:
    HttpResponse()
    {
    }
    ~HttpResponse()
    {
    }

public:
    string respBuffer;
};